package com.heiko.bloom.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.material.Card
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.heiko.bloom.R
import com.heiko.bloom.data.ImageItem
import com.heiko.bloom.ui.theme.h2
import com.heiko.bloom.ui.theme.white

@Composable
fun ThemeCard(item: ImageItem) {
    Card(elevation = 5.dp, modifier = Modifier.padding(6.dp)) {
        Surface(
            color = white
        ) {
            Box(
                modifier = Modifier
                    .height(136.dp)
                    .width(136.dp)
            ) {
                Image(
                    painter = painterResource(id = item.resId),
                    contentDescription = null,
                    modifier = Modifier.height(96.dp),
                    contentScale = ContentScale.Crop
                )
                Text(
                    text = item.name,
                    style = h2,
                    overflow = TextOverflow.Ellipsis,
                    maxLines = 1,
                    modifier = Modifier
                        .align(Alignment.BottomStart)
                        .padding(start = 16.dp, end = 16.dp, bottom = 12.dp)
                        .fillMaxWidth()
                )
            }
        }
    }
}

@Preview
@Composable
fun ThemeCardPreview() {
    ThemeCard(ImageItem("Desert chic", R.drawable.desert_chic))
}